package marvin.webapp.audio.action;

import javax.annotation.PostConstruct;
import javax.faces.bean.ManagedBean;
import javax.faces.bean.SessionScoped;

import marvin.webapp.audio.client.MarvinClient;
import marvin.webapp.audio.subscription.SubscriptionServer;
import marvin.webapp.common.action.AbstractWebAction;

@ManagedBean
@SessionScoped
public class StandardAction extends AbstractWebAction {

	private static final long serialVersionUID = 7015153638601208133L;
	private String welcomemessage = "Welcome";
	public static final Integer SUBSCRIPTION_PORT = 4242;

	private static SubscriptionServer subServer;
	
	@PostConstruct
	public void load() {
		startSubscriptionServer();
	}

	public String getWelcomemessage() {
		return welcomemessage;
	}
	
	private void startSubscriptionServer(){
		if(subServer == null){
			subServer = new SubscriptionServer(SUBSCRIPTION_PORT);
			subServer.start();
			
			MarvinClient.startClient();
		}
	}
	
	public SubscriptionServer getServer() {
		return subServer;
	}
}
